<?php
/**
 * The template for displaying the footer.
 *
 * @package WordPress
 * @subpackage Sastro
 * @since Sastro 1.0
 */
 
                $shortname = THE_SHORTNAME;
				$initial = THE_INITIAL;
				
                $pid = nvr_get_postid();
                $custom = nvr_get_customdata($pid);
				
                $pagelayout = nvr_get_sidebar_position($pid);
				
				$sectionbuilders = array();
				if(isset( $custom['_'.$initial.'_sectionbuilder'][0] )){
                    $sectionbuilders = unserialize($custom['_'.$initial.'_sectionbuilder'][0]);
                }
				
                if($pagelayout!='one-col'){ 
                ?>
                
                        <div class="clearfix"></div>
                    </div><!-- main -->
                </section><!-- content -->
                <aside id="sidebar" class="four columns <?php if($pagelayout=="two-col-left"){echo "positionright";}else{echo "positionleft";}?>">
                    <?php get_sidebar();?>  
                </aside><!-- sidebar -->
                
                <?php 
                } 
                ?>
            
                <div class="clearfix"></div>
            </section><!-- maincontent -->
            </div>
        </div>
        </div>
    </div>
    <!-- END MAIN CONTENT -->
    
    <!-- SECTION BUILDER -->
    <?php 
	nvr_section_builder($sectionbuilders);
	?>
    <!-- END SECTION BUILDER -->
    
    <?php 
	$enableaftercontent = nvr_get_option( $shortname . '_enable_aftercontent');
	$aftercontent = nvr_get_option( $shortname . '_aftercontent_text');
	$aftercontent 	= (isset($custom['_'.$initial.'_aftercontent_text'][0]) && $custom['_'.$initial.'_aftercontent_text'][0]!="")? $custom['_'.$initial.'_aftercontent_text'][0] : $aftercontent;
	if($enableaftercontent && $aftercontent){ 
	?>
    <!-- AFTER CONTENT -->
    <div id="outeraftercontent">
        <div class="container">
            <section id="aftercontent" class="row">
                <div class="twelve columns">
                    <?php echo do_shortcode($aftercontent); ?>
                    <div class="clearfix"></div>
                </div>
                <div class="clearfix"></div>
            </section>
        </div>
    </div>
    <!-- END AFTER CONTENT -->
    <?php }// end if($aftercontent!="") ?>
    
    </div>
    <!-- END MIDDLE -->

<?php
$footcol_scheme = array(
	'0;none',
	'1;twelve columns',
	'2;three columns alpha-nine columns last',
	'2;six columns alpha-six columns last',
	'2;nine columns alpha-three columns last',
	'3;three columns alpha-six columns-three columns last',
	'3;three columns alpha-three columns-six columns last',
	'3;six columns alpha-three columns-three columns last',
	'3;four columns alpha-four columns-four columns last',
	'4;three columns alpha-three columns-three columns-three columns last'
);

$shortname = THE_SHORTNAME;

$opt_footerLayout = intval(nvr_get_option($shortname. '_footer_sidebar_layout',8));

$disablefootersidebar = nvr_get_option($shortname. '_disable_footer_sidebar');

if( is_home() ){
	$pid = get_option('page_for_posts');
}else{
	$pid = get_the_ID();
}

$custom = nvr_get_customdata($pid);
$cf_footerLayout	= (isset($custom["layout_footer"][0]) && (intval($custom["layout_footer"][0])>=0 && intval($custom["layout_footer"][0])<=8) )? intval($custom["layout_footer"][0]) : $opt_footerLayout; 

$footcol = explode(';',$footcol_scheme[$cf_footerLayout]);
$footclass = explode('-',$footcol[1]);
?>
	<div id="footerwrapper">
<?php
if(!$disablefootersidebar){
?>			
        <!-- FOOTER SIDEBAR -->
        <div id="outerfootersidebar">
        	<div class="container">
                <div id="footersidebarcontainer" class="row"> 
                    <footer id="footersidebar">
                    <?php for($i=0;$i<$footcol[0];$i++){ $numfootcol = $i+1; ?>
                    
                    <div id="footcol<?php echo $numfootcol; ?>"  class="<?php echo $footclass[$i]; ?>">
                        <div class="widget-area">
                            <?php if ( ! dynamic_sidebar( 'footer'.$numfootcol ) ) : ?><?php endif; // end general widget area ?>
                        </div>
                    </div>
                    
                    <?php } ?>
                        <div class="clearfix"></div>
                    </footer>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <!-- END FOOTER SIDEBAR -->
<?php
}
?>
        <!-- FOOTER -->
        <div id="outerfooter">
        	<div class="container">
                <div id="footercontainer" class="row">
                    <footer id="footer" class="twelve columns">
                        <div class="copyrightcontainer">
                            <div class="copyright"><?php nvr_footer_text(); ?></div>
                            <nav id="footermenu">
                            <?php wp_nav_menu( array(
                              'container'       => 'ul', 
                              'menu_class'      => 'sf-menu',
                              'menu_id'         => 'footernav', 
                              'depth'           => 1,
                              'sort_column'    => 'menu_order',
                              'theme_location' => 'secondarymenu' 
                              )); 
                            ?>
                            </nav><!-- nav -->	
                            <div class="clearfix"></div>
                        </div>
                    </footer>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <!-- END FOOTER -->
	</div>
        
	</div><!-- end bodychild -->
</div><!-- end outercontainer -->
<?php 
	/* Always have wp_footer() just before the closing </body>
	 * tag of your theme, or you will break many plugins, which
	 * generally use this hook to reference JavaScript files.
	 */

	wp_footer();
	
	$trackingcode = stripslashes(nvr_get_option( $shortname . '_trackingcode'));
	if($trackingcode!=""){
		echo '<script type="text/javascript">';
		echo $trackingcode;
		echo '</script>';
	}
?>
</body>
</html>
